package com.thl.levelcache.service;

import com.thl.levelcache.annotation.LvCache;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 使用案例demo
 *
 * @author zhao yi
 * @create 2020-05-24 11:13
 * @desc
 **/
@Slf4j
@RestController
public class DemoService {

    @LvCache
    @GetMapping("/getUserList")
    public List<HashMap> getUserList() {
        List<HashMap> userList = getUserListByDb();
        log.info("查询数据库信息>>>>>");
        return userList;
    }

    /***
     * 伪代码
     * 查询用户信息,访问数据库
     * @return
     */
    private List<HashMap> getUserListByDb() {
        List<HashMap> userList = new ArrayList<>();
        HashMap user = null;
        for (int i = 0; i < 10; i++) {
            user = new HashMap();
            user.put("id", ++i);
            user.put("age", "18");
            user.put("name", "zhangsan");
            user.put("sex", "1");
            user.put("dataTime", new Date());
            userList.add(user);
        }

        return userList;
    }

}
